<template>
	<view>
		<web-view :src="url" @message="getMessage" @load="bindload"></web-view>
	</view>
</template>

<script type="text/javascript" src="https://public-1251849568.cos.ap-guangzhou.myqcloud.com/jssdk/finclip-jssdk-1.4.2.js"></script>
<script>
	export default {
		data() {
			return {
				url: '',
				device: {},
				data: '',
				addType: 1,
			}
		},
		onUnload() {
			if (this.addType == 2) {
				uni.navigateBack({
					delta: 2
				})
			}
		},
		onHide() {
			uni.navigateBack({})
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.device.deviceName
			})
		},
		onLoad(opt) {
			this.device = JSON.parse(decodeURIComponent(opt.device))
			console.log('opt', this.device);
			this.addType = this.device.addType || 1
			let topHeight = 15 //uni.getStorageSync('navHeight')
			let barHeight = 30 //uni.getStorageSync('navHeight')//uni.getStorageSync('statusBarHeight')
			let margin = 30
			let bottomHeight = 30
			let envType = 1
			let devData = {
				adminToken: this.device.adminToken,
				devIcon: this.device.devIcon,
				devId: this.device.deviceNo,
				devName: this.device.deviceName,
				groupId: this.device.userGroupId,
				roomId: this.device.roomId
			}
			let uiUrl = this.device.uiUrl
			let param = ''
			if (this.device.uiUrl.includes('?')) {
				uiUrl = this.device.uiUrl.split('?')[0]
				param = this.device.uiUrl.split('?')[1]
			}
			let url =
				`${uiUrl}?authorization=${uni.getStorageSync('accessToken')}&appKey=${getApp().globalData.api.appKey}&lang=zh&sn=${this.device.deviceNo}&topHeight=${topHeight}&barHeight=${barHeight}&margin=${margin}&envType=${envType}&devData=${(encodeURIComponent(encodeURIComponent(JSON.stringify(devData))))}&bottomHeight=${bottomHeight}&type=1&${param}`
			this.url = url
			console.log(url);
			uni.setNavigationBarTitle({
				title: this.device.deviceName
			})
		},
		methods: {
			getMessage(e) {
				wx.requestPluginPayment({
					version: 'develop',
					fee: 1,
					paymentArgs: {},
					currencyType: 'CNY',
					success(res) {},
					fail(res) {}
				})
			},
			bindload(ev) {},
		}
	}
</script>

<style>

</style>
